package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.ReportDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportDao reportDao;

    //获取所有运营情况数据
    public Map<String, Object> getBusinessReportData() throws Exception {
        //获取当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周第一天的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月的第一天
        String thisWeekMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //获取今日新增会员数
        int todayNewMember = reportDao.findMemberCountByToday(today);
        //获取总的会员数
        int totalMember = reportDao.findMembetCount();
        //获取本周新增会员数
        int thisWeekNewMember = reportDao.findMemberCountByWeek(thisWeekMonday);
        //获取本月新增会员数
        int thisMonthNewMember = reportDao.findMemberCountByMonth(thisWeekMonth);
        //获取今日预约数
        int todayOrderNumber = reportDao.findOrderCountByToday(today);
        //获取本周预约数
        int thisWeekOrderNumber = reportDao.findOrderCountByWeek(thisWeekMonday);
        //获取本月预约数
        int thisMonthOrderNumber = reportDao.findByOrderCountByMonth(thisWeekMonth);
        //获取今天实际预约人数
        int todayVisitsNumber = reportDao.findOrderVisitsCountToday(today);
        //获取本周实际到诊人数
        int thisWeekVisitsNumber = reportDao.findOrderVisitsCountWeek(thisWeekMonday);
        //获取本月实际到诊人数
        int thisMonthVisitsNumber = reportDao.findOrderVisitCountMonth(thisWeekMonth);
        //获取热门套餐，包括套餐名称，预约人数，预约人数占总预约人数占比
        List<Map> hotSetmeal = reportDao.findSetmeal();

        Map map = new HashMap();
        map.put("reportDate" , today);
        map.put("todayNewMember" , todayNewMember);
        map.put("totalMember" , totalMember);
        map.put("thisWeekNewMember" , thisWeekNewMember);
        map.put("thisMonthNewMember" , thisMonthNewMember);
        map.put("todayOrderNumber" , todayOrderNumber);
        map.put("thisWeekOrderNumber" , thisWeekOrderNumber);
        map.put("thisMonthOrderNumber" , thisMonthOrderNumber);
        map.put("todayVisitsNumber" , todayVisitsNumber);
        map.put("thisWeekVisitsNumber" , thisWeekVisitsNumber);
        map.put("thisMonthVisitsNumber" , thisMonthVisitsNumber);
        map.put("hotSetmeal" , hotSetmeal);
        return map;
    }
}
